import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import eslintPlugin from 'vite-plugin-eslint'
import Components from 'unplugin-vue-components/vite'
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
import vueI18n from '@intlify/vite-plugin-vue-i18n'

// https://vitejs.dev/config/
export default ({ mode }) => {
  const env = loadEnv(mode, process.cwd())
  console.log(env, mode, 'env文件内容')
  return defineConfig({
    plugins: [
      vue(),
      Components({
        dirs: ['src'], // 配置需要默认导入的自定义组件文件夹，该文件夹下的所有组件都会自动 import
        dts: true, // 启用ts支持
        resolvers: [
          AntDesignVueResolver({
            importStyle: 'less',
            resolveIcons: true // 自动引入图标库
          }) // 配置按需加载支持
        ]
      }),
      eslintPlugin({
        exclude: ['./node_modules/**'],
        cache: false
      }),
      vueI18n({
        //预编译，解决i8n警告问题
        include: resolve(__dirname, 'i18n/**')
      })
    ],
    base: '/manageThah/',
    css: {
      preprocessorOptions: {
        less: {
          modifyVars: {
            // 在这里自定义主题色等样式 https://github.com/vueComponent/ant-design-vue/blob/main/components/style/themes/default.less
            // 'primary-color': '#1da57a',
            // 'link-color': '#1da57a',
            // 'border-radius-base': '2px'
          },
          javascriptEnabled: true
        }
      }
    },
    server: {
      host: '0.0.0.0',
      open: true,
      proxy: {
        '/mth': {
          target: 'https://manage.tanhuiah.com/mth',
          changeOrigin: true,
          rewrite: path => path.replace(/^\/mth/, '')
        }
      }
    },
    resolve: {
      alias: {
        '@': resolve(__dirname, 'src')
      }
    },
    build: {
      outDir: 'manageThah', //打包出来的文件夹名称
      assetsDir: 'static', //打包出来的静态资源文件夹名称
      minify: 'terser',
      terserOptions: {
        compress: {
          drop_console: false, // 清除console
          drop_debugger: true // 清除debugger
        }
      }
    }
  })
}
